#Boa:Dialog:Dialog1

import wx
import utiles

def create(parent):
    return Dialog1(parent)

[wxID_DIALOG1, wxID_DIALOG1BUTTON1, wxID_DIALOG1BUTTON2, 
 wxID_DIALOG1COMBOBOX1, wxID_DIALOG1STATICTEXT4, wxID_DIALOG1STATICTEXT9, 
 wxID_DIALOG1TEXTCTRL4, wxID_DIALOG1TEXTCTRL9, 
] = [wx.NewId() for _init_ctrls in range(8)]

class Dialog1(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
              pos=wx.Point(384, 146), size=wx.Size(467, 200),
              style=wx.DEFAULT_DIALOG_STYLE, title='Devolucion: Observaciones')
        self.SetClientSize(wx.Size(459, 173))

        self.staticText4 = wx.StaticText(id=wxID_DIALOG1STATICTEXT4,
              label='Proveedor', name='staticText4', parent=self,
              pos=wx.Point(16, 8), size=wx.Size(50, 13), style=0)

        self.textCtrl4 = wx.TextCtrl(id=wxID_DIALOG1TEXTCTRL4, name='textCtrl4',
              parent=self, pos=wx.Point(16, 24), size=wx.Size(256, 21), style=0,
              value='')
        self.textCtrl4.SetEditable(False)

        self.staticText9 = wx.StaticText(id=wxID_DIALOG1STATICTEXT9,
              label='Observaciones', name='staticText9', parent=self,
              pos=wx.Point(16, 48), size=wx.Size(71, 13), style=0)

        self.textCtrl9 = wx.TextCtrl(id=wxID_DIALOG1TEXTCTRL9, name='textCtrl9',
              parent=self, pos=wx.Point(16, 64), size=wx.Size(432, 21), style=0,
              value='')
        self.textCtrl9.SetMaxLength(250)
        self.textCtrl9.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)

        self.comboBox1 = wx.ComboBox(choices=[], id=wxID_DIALOG1COMBOBOX1,
              name='comboBox1', parent=self, pos=wx.Point(16, 96),
              size=wx.Size(130, 21), style=0, value='')
        self.comboBox1.Show(False)
        self.comboBox1.SetLabel('')

        self.button1 = wx.Button(id=wxID_DIALOG1BUTTON1, label='Guardar',
              name='button1', parent=self, pos=wx.Point(192, 136),
              size=wx.Size(75, 23), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnGuardar, id=wxID_DIALOG1BUTTON1)

        self.button2 = wx.Button(id=wxID_DIALOG1BUTTON2, label='Salir',
              name='button2', parent=self, pos=wx.Point(373, 136),
              size=wx.Size(75, 23), style=0)
        self.button2.Bind(wx.EVT_BUTTON, self.OnSalir, id=wxID_DIALOG1BUTTON2)

    def __init__(self, parent, proveedor="", temporada=False):
        self._init_ctrls(parent)
        if proveedor=="": self.Close()
        self.llenarCombo()
        self.marca = False
        if temporada:
            self.comboBox1.Show(True)
            self.marca = True
        self.textCtrl4.SetLabel(proveedor)
        self.observaciones = ""

    def llenarCombo(self):
        anio = int(utiles.obtenerFecha("Y-m-d")[:4])
        mes = int(utiles.obtenerFecha("Y-m-d")[5:7])
        dia = int(utiles.obtenerFecha("Y-m-d")[-2:])
        anioanterior = anio -1
        anioactual = anio
        aniosiguiente = anio + 1
        self.comboBox1.Append("INVIERNO"+str(anioanterior))
        self.comboBox1.Append("VERANO"+str(anioanterior))
        self.comboBox1.Append("INVIERNO"+str(anioactual))
        self.comboBox1.Append("VERANO"+str(anioactual))
        self.comboBox1.Append("INVIERNO"+str(aniosiguiente))
        self.comboBox1.Append("VERANO"+str(aniosiguiente))
        self.comboBox1.SetEditable(False)

    def OnGuardar(self, event):
        temporada = self.comboBox1.GetLabel()
        if self.marca:
            if temporada=="":
                utiles.mensaje(None,"Debe ingresar una temporada")
                self.comboBox1.SetFocus()
                return
        if temporada != "":
            temporada = " / "+temporada
        self.observaciones = self.textCtrl9.GetLabel()+temporada
        self.Close()

    def OnSalir(self, event):
        self.Close()

    def getObservacion(self):
        return self.observaciones

    def OnKillFocus(self, event):
        self.textCtrl9.SetLabel((self.textCtrl9.GetLabel()).upper())
